//
// Created by root on 2019/9/26.
//

#include "Manager.h"
#include "Phone.h"
#include "AOADev.h"

Manager::Manager() : m_bQuit(false) {
    m_mode.push_back(new Phone);
    m_mode.push_back(new AOADev);
}

Manager::~Manager() {
    for (auto &c : m_mode) {
        delete c;
    }
}

void Manager::run() {
    m_HotPlug.waitPhoneIn();
    while (!m_bQuit) {
        if (m_HotPlug.arrEvent()) {
            libusb_device *device = m_HotPlug.getDev();
            for (auto &itr: m_mode) {
                if (itr->IsBelong(device, 0)) {
                    itr->handle(device, this);
                }
            }
        } else {
            sleep(1);
        }
    }
}

void Manager::setAoAPhoneAttach(AOAaudio *ptr) {
    m_phoneAttch.reset(ptr);
}
